<?php

namespace App\Repository;

use App\Models\Tag;
use Illuminate\Support\Arr;

Class TagRepository
{
    /**
     * 列表
     *
     * @param object $request
     * @return void
     */
    public function getList($request)
    {
        $list = Tag::query()->orderBy('id','desc')->paginate(Arr::get($request->input(), 'limit', 10));
        return $list;
    }

    /**
     * 添加或更新方法
     *
     * @param object $request
     * @return void
     */
    public function addOrUpdate($request)
    {
        $tag = Tag::firstOrNew(['id'=>$request->id]);
        $data = Arr::except($request->input(),['id']);
        $tag->is_show = $request->is_show ?:0;
        $tag->fill($data);
        return $tag ->save();
    }

    /**
     * 删除
     *
     * @param object $request
     * @return void
     */
    public function destory($request)
    {
        return Tag::destroy($request->id);   
    }

    public function getInfo($request)
    {
        return Tag::findOrFail($request->id);
    }


    public function getTags($request)
    {
        $request->merge(['is_show'=>1]);
        return Tag::query()->orderBy('id','desc')->search($request->input())->paginate(Arr::get($request->input(), 'limit', 10));
    }

}